package com.bw.lib_storage.db.dao

import androidx.room.Dao
import androidx.room.Delete
import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Update
import com.bw.lib_storage.db.entity.SearchEntity

@Dao
interface SearchDao {
    @Insert(onConflict = OnConflictStrategy.REPLACE)
    fun insert(searchEntity: SearchEntity)

    @Insert
    fun insertAll(vararg searchEntity: SearchEntity)

    @Delete
    fun deleteSearch(searchEntity: SearchEntity)

    @Update
    fun updateSearch(searchEntity: SearchEntity)

    @Query("SELECT * FROM search")
    fun getAllSearch():List<SearchEntity>

    @Query("SELECT * FROM search WHERE title LIKE '%'+:title+'%'")
    fun getSearchByTitle(title:String):List<SearchEntity>
    
    @Query("SELECT * FROM search WHERE title = :title")
    fun getSearchByExactTitle(title:String):SearchEntity?
    
    @Query("DELETE FROM search WHERE title = :title")
    fun deleteByTitle(title:String)
    
    @Query("DELETE FROM search")
    fun deleteAll()
}